package com.randb.easyhttp.utils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.InputStream;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.BufferedSink;
import okio.Okio;
import okio.Source;

/**
 * User: RandBII
 * Date: 2020/5/29
 * Description:
 */
public class RequestBodyUtils {

    public static RequestBody create(final MediaType mediaType, final InputStream inputStream) {

        return new RequestBody() {
            @Nullable
            @Override
            public MediaType contentType() {
                return mediaType;
            }

            @Override
            public void writeTo(@NotNull BufferedSink bufferedSink) throws IOException {
                Source source = null;
                source = Okio.source(inputStream);
                bufferedSink.writeAll(source);
            }
        };
    }


}
